const Router = require('koa-router')
const router = new Router()

const { oauth2callback, checkAuth } = require('../google/gmail')
const { readSheet, updateSheet } = require('../google/sheet')

// 回调
router.get('/auth', async (ctx) => {
    ctx.body = await checkAuth()
});

router.get('/readSheet', async (ctx) => {
    ctx.body = await readSheet('birthDate')
});

router.get('/update', async (ctx) => {
    ctx.body = await updateSheet(`文案!B26:B26`, [[1]])
});

// 回调
router.get('/callback', async (ctx) => {
    ctx.body = await oauth2callback(ctx.request.query.code)
});

module.exports = router